package com.nf.health.app.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.MyApplication;
import com.nf.health.app.R;
import com.nf.health.app.utils.DensityUtil;

/**
 * 功能： 列表空界面显示
 * 用于listView ，GridView ，RecycleView 的setEmpety方法
 * @author yuyahao
 * 备注： 其他童鞋们可对其进行拓展 eg: 添加监听，切换布局
 */
public class EmptyView extends LinearLayout {
    private TextView  tv_no_message;
    private TextView  tv_no_message2;
    private ImageView iv_empety_mageger;
    private LinearLayout ll_no_manager;
    private LinearLayout ll_no_message_root;
    public EmptyView(Context context) {
        super(context);
        init();
        // TODO Auto-generated constructor stub
    }

    public EmptyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.empty_view, null);
        iv_empety_mageger = (ImageView) view.findViewById(R.id.iv_empety_mageger);
        tv_no_message = (TextView) view.findViewById(R.id.tv_no_message);
        tv_no_message2 = (TextView) view.findViewById(R.id.tv_no_message2);
        ll_no_manager = (LinearLayout) view.findViewById(R.id.ll_no_manager);
        ll_no_message_root = (LinearLayout) view.findViewById(R.id.ll_no_message_root);
        tv_no_message2.setVisibility(GONE);
        addView(view);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        setMeasuredDimension(widthSize,heightSize);

    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        super.onWindowFocusChanged(hasWindowFocus);
    }

    /**
     * 一定要调用该方法
     * @param
     */
    public EmptyView mustCallInitWay(View view){
        if(view != null){
          ViewGroup.LayoutParams  params = ll_no_message_root.getLayoutParams();
            params.width = android.widget.LinearLayout.LayoutParams.MATCH_PARENT;
            params.height = android.widget.LinearLayout.LayoutParams.MATCH_PARENT;
            ((ViewGroup)view.getParent()).addView(this,params);
        }
        return this;
    }
    /**
     * 设置图片的大小
     * @param
     */
    public EmptyView setImageViewParams(int widthdp,int heightdp){
        ViewGroup.LayoutParams params =  iv_empety_mageger.getLayoutParams();
        params.height = DensityUtil.dip2px(MyApplication.getContext(),widthdp);
        params.width = DensityUtil.dip2px(MyApplication.getContext(),heightdp);
        iv_empety_mageger.setLayoutParams(params);
        return this;
    }
    public EmptyView setNoMessageText(CharSequence text) {
        tv_no_message.setText(text);
        tv_no_message.setVisibility(View.VISIBLE);
        return this;
    }
    /********修改文字的颜色**********/
    public EmptyView  setMessageTextColor2(int colorResId) {
    	tv_no_message.setTextColor(colorResId);
    	tv_no_message.setVisibility(View.VISIBLE);
        return this;
    }
    public EmptyView setOnRefreshData(OnClickListener onClickListener){
        tv_no_message.setOnClickListener(onClickListener);
        tv_no_message2.setOnClickListener(onClickListener);
        iv_empety_mageger.setOnClickListener(onClickListener);
        return this;
    }

    /**
     * 是否显示刷新提示
     * @param visisble
     * @return
     */
    public EmptyView setMyRefreshShow(int visisble){
        if(visisble ==View.VISIBLE || visisble == GONE || visisble == INVISIBLE){
            tv_no_message2.setVisibility(visisble);
        }
        return this;
    }
    /**
     * 显示不同的文字提示及其图片提示
     */
    public EmptyView setMyManager(String showNoTip,int showNoIamgeViewResId,int textSize,int colorResId){
        iv_empety_mageger.setImageResource(showNoIamgeViewResId);
        tv_no_message.setTextColor(colorResId);
        tv_no_message.setText(showNoTip);
        tv_no_message.setTextSize(textSize);
        tv_no_message.setVisibility(View.VISIBLE);
        return this;
    }
    /**
     * 显示不同的文字提示及其图片提示
     */
    public EmptyView setMyManager(String showNoTip,int showNoIamgeViewResId){
        iv_empety_mageger.setImageResource(showNoIamgeViewResId);
        tv_no_message.setText(showNoTip);
        tv_no_message.setVisibility(View.VISIBLE);
        return this;
    }
    /**
     * 显示不同的文字提示及其图片提示
     */
    public EmptyView setMyManager(int showNoIamgeViewResId){
        iv_empety_mageger.setImageResource(showNoIamgeViewResId);
        iv_empety_mageger.setVisibility(View.VISIBLE);
        return this;
    }

    /**
     * 显示不同的文字提示
     */
    public EmptyView setMyManager(String showNoTip){
        tv_no_message.setText(showNoTip);
        tv_no_message.setVisibility(View.VISIBLE);
        return this;
    }
    /**
     * 是否显示文字
     */
    public EmptyView isShowTextTipMassager(boolean isShow){
        if(isShow){
            tv_no_message.setVisibility(View.VISIBLE);
        }
        return this;
    }
    /**
     * 是否显示文字
     */
    public EmptyView isShowTextTipMassager(boolean isShow,String showNoTip){
        if(isShow){
            tv_no_message.setVisibility(View.VISIBLE);
            tv_no_message.setText(showNoTip);
        }else{
            tv_no_message.setVisibility(View.GONE);
            tv_no_message.setText(showNoTip);
        }
        return this;
    }
    /**
     * 是否显示图片
     */
    public EmptyView isShowIamgeMassager(boolean isShow,int showNoIamgeViewResId){
        if(isShow){
            iv_empety_mageger.setVisibility(View.VISIBLE);
            iv_empety_mageger.setImageResource(showNoIamgeViewResId);
        }else{
            iv_empety_mageger.setVisibility(View.GONE);
        }
        return this;
    }
    /**
     * 是否显示图片
     */
    public EmptyView isShowIamgeMassager(boolean isShow){
        if(isShow){
            iv_empety_mageger.setVisibility(View.VISIBLE);
        }else{
            iv_empety_mageger.setVisibility(View.GONE);
        }
        return this;
    }
}
